//
//  GGTReviewTableViewCell.m
//  GGT
//
//  Created by 空空空 on 14/11/5.
//  Copyright (c) 2014年 GGT. All rights reserved.
//

#import "GGTReviewTableViewCell.h"
#import "AksStraightPieChart.h"
@implementation GGTReviewTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        self.goodLabel = [[UILabel alloc]init];
        [self.contentView addSubview:self.goodLabel];
        self.label = [[UILabel alloc]init];
        self.straightPieChart = [[AksStraightPieChart alloc]init];
              }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.label.frame = CGRectMake(10, 10, self.contentView.frame.size.width, self.contentView.frame.size.height / 3);
    self.label.text = @"评价率";
    [self.contentView addSubview:self.label];
    self.goodLabel.frame = CGRectMake(self.contentView.frame.size.width / 6 * 5 - 15, self.contentView.frame.size.height / 3 * 2 - 18, self.contentView.frame.size.width / 3, self.contentView.frame.size.height / 3);
    self.straightPieChart.frame = CGRectMake(20, self.contentView.frame.size.height / 3 * 2 - 10, self.contentView.frame.size.width - 100, 10);
    [self.contentView addSubview:self.straightPieChart];
    [self.straightPieChart clearChart];
    
    self.totalScore = [self totalScorefirst:[self.detail.service_score intValue] second:[self.detail.decoration_score intValue] thrid:[self.detail.product_score intValue]];
    self.score = ([self.detail.service_score floatValue] + [self.detail.decoration_score floatValue] + [self.detail.product_score floatValue]) / self.totalScore * 100;
    
    if (self.score > 0) {
        
        [self.straightPieChart addDataToRepresent:self.score WithColor:[UIColor orangeColor]];
        [self.straightPieChart addDataToRepresent:100 - self.score WithColor:[UIColor grayColor]];
    } else {
        [self.straightPieChart addDataToRepresent:100 WithColor:[UIColor grayColor]];
    }
    if (self.score > 0) {
        self.goodLabel.text = [NSString stringWithFormat:@"%d%%", self.score];
    } else {
        self.goodLabel.text = @"暂无";
    }

}
- (float)totalScorefirst:(float)fir
                  second:(float)sec
                   thrid:(float)thr;
{
    float total = 30.0;
    if (fir == 0) {
        total = total - 10;
    }
    if (sec == 0) {
        total = total - 10;
    }
    if (thr == 0) {
        total = total - 10;
    }
    return total;
}
- (void)dealloc
{
    [_goodLabel release];
    [_detail release];
    [_label release];
    [_straightPieChart release];
    [super dealloc];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
